import smtplib
from email.mime.text import MIMEText




#设置服务器所需信息
#163邮箱服务器地址
mail_host = 'smtp.gmail.com'
#163用户名
mail_user = 'hand***u666'
#密码(部分邮箱为授权码)
mail_pass = '****'
#邮件发送方邮箱地址
sender = 'handso***@gmail.com'
#邮件接受方邮箱地址，注意需要[]包裹，这意味着你可以写多个邮件地址群发
receivers = ['1307***@qq.com','capta***e@gmail.com']

#设置email信息
#邮件内容设置
content = 'I am ws gmail' \
          ',how are you recently.\n,By the way, I want to know what time we have to class today'

message = MIMEText(content,'plain','utf-8')
#邮件主题
message['Subject'] = 'Hello Mr.Xie'
#发送方信息
message['From'] = sender
#接受方信息
message['To'] = receivers[1]

#登录并发送邮件
try:
    smtpObj = smtplib.SMTP_SSL(mail_host)
    #1. 连接到服务器
    smtpObj.connect(mail_host,465)

    #2. 登录到服务器
    smtpObj.login(mail_user,mail_pass)
    #发送
    smtpObj.sendmail(
        sender,receivers,message.as_string())
    #退出
    smtpObj.quit()
    print('success')
except smtplib.SMTPException as e:
    print('error',e) #打印错误